import request from '@/utils/request'

// 查询广告策略列表
export function listStrategy(query) {
  return request({
    url: '/advertisement/strategy/list',
    method: 'get',
    params: query
  })
}

// 查询广告策略详细
export function getStrategy(strategyId) {
  return request({
    url: '/advertisement/strategy/' + strategyId,
    method: 'get'
  })
}

// 新增广告策略
export function addStrategy(data) {
  return request({
    url: '/advertisement/strategy',
    method: 'post',
    data: data
  })
}

// 修改广告策略
export function updateStrategy(data) {
  return request({
    url: '/advertisement/strategy',
    method: 'put',
    data: data
  })
}

// 删除广告策略
export function delStrategy(strategyId) {
  return request({
    url: '/advertisement/strategy/' + strategyId,
    method: 'delete'
  })
}

// 批量删除广告策略
export function delStrategies(strategyIds) {
  return request({
    url: '/advertisement/strategy/' + strategyIds,
    method: 'delete'
  })
}

// 启用/停用广告策略
export function toggleStrategyStatus(strategyId, status) {
  return request({
    url: '/advertisement/strategy/status',
    method: 'put',
    data: {
      strategyId: strategyId,
      status: status
    }
  })
}

// 批量启用/停用广告策略
export function batchToggleStrategyStatus(strategyIds, status) {
  return request({
    url: '/advertisement/strategy/batch/status',
    method: 'put',
    data: {
      strategyIds: strategyIds,
      status: status
    }
  })
}

// 复制广告策略
export function copyStrategy(strategyId, newName) {
  return request({
    url: '/advertisement/strategy/copy/' + strategyId,
    method: 'post',
    data: {
      newName: newName
    }
  })
}

// 根据设备ID获取策略
export function getStrategyByDevice(deviceId) {
  return request({
    url: '/advertisement/strategy/device/' + deviceId,
    method: 'get'
  })
}

// 获取策略关联的设备列表
export function getStrategyDevices(strategyId) {
  return request({
    url: '/advertisement/strategy/' + strategyId + '/devices',
    method: 'get'
  })
}

// 设置策略关联的设备
export function setStrategyDevices(strategyId, deviceIds) {
  return request({
    url: '/advertisement/strategy/' + strategyId + '/devices',
    method: 'post',
    data: {
      deviceIds: deviceIds
    }
  })
}

// 获取策略关联的素材列表
export function getStrategyMaterials(strategyId) {
  return request({
    url: '/advertisement/strategy/' + strategyId + '/materials',
    method: 'get'
  })
}

// 设置策略关联的素材
export function setStrategyMaterials(strategyId, materialIds) {
  return request({
    url: '/advertisement/strategy/' + strategyId + '/materials',
    method: 'post',
    data: {
      materialIds: materialIds
    }
  })
}

// 获取可用设备列表
export function getAvailableDevices() {
  return request({
    url: '/device/list/available',
    method: 'get'
  })
}

// 获取可用素材列表
export function getAvailableMaterials() {
  return request({
    url: '/advertisement/material/list/available',
    method: 'get'
  })
}

// 导出广告策略
export function exportStrategy(query) {
  return request({
    url: '/advertisement/strategy/export',
    method: 'post',
    params: query,
    responseType: 'blob'
  })
}

// 预览策略效果
export function previewStrategy(strategyId) {
  return request({
    url: '/advertisement/strategy/preview/' + strategyId,
    method: 'get'
  })
}
